<template>
  <div class="flex-wrap m-t-tiny">
    <div
      v-for="legend in legends"
      :key="legend.field"
      class="m-v-tiny pie-legend d-flex-c ai-c"
      :class="extendClass"
    >
      <div
        class="color-rect "
        :style="{color:legend.color}"
      >
        <div class="flex-ai-c">
          <div
            class="f-20 ff-agencyyr f-w7 c-pointer"
            @click="$emit('select',legend.field)"
          >
            {{ valueData[legend.field] }}
          </div>
          <div
            class="f-12 c-white legend-unit"
            v-if="legend.unit"
          >
            {{ legend.unit }}
          </div>
        </div>

        <div class="f-12 c-white">
          {{ legend.name }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PieChartLegend',
  props: {
    legends: {
      type: Array,
      required: true,
      default: () => []
    },
    valueData: {
      type: Object,
      required: true,
      default: () => {}
    },
    extendClass: {
      type: String,
      default: ''
    }
  },
  data () {
    return {

    }
  }
}
</script>

<style lang="scss" scoped>
.pie-legend {
  .legend-unit {
    margin-left: 3px;
  }

  .color-rect {
    position: relative;
    padding-left: 10px;

    &::before {
      content: "";
      background-color: currentcolor;
      position: absolute;
      top: 5px;
      left: -20px;
      width: 10px;
      height: 10px;
    }
  }
}
</style>
